<?php

namespace iBrand\Member\Backend\Providers;

use iBrand\Member\Backend\Console\MemberBackendMenusCommand;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;

class BackendServiceProvider extends ServiceProvider
{
	/**
	 * This namespace is applied to your controller routes.
	 *
	 * In addition, it is set as the URL generator's root namespace.
	 *
	 * @var string
	 */
	protected $namespace = 'iBrand\Member\Backend\Http\Controllers';

	/**
	 * Define your route model bindings, pattern filters, etc.
	 */
	public function boot()
	{
		if (!$this->app->routesAreCached()) {
			$this->mapWebRoutes();
		}

		$this->loadViewsFrom(__DIR__ . '/../../resources/views', 'member-backend');

		if ($this->app->runningInConsole()) {
			$this->publishes([
				__DIR__ . '/../../resources/assets/template' => public_path('assets/template'),
			], 'member-backend-assets');

			$this->publishes([
				__DIR__ . '/../../resources/assets/libs' => public_path('assets/backend/libs'),
			], 'member-backend-assets-libs');

			$this->publishes([
				__DIR__ . '/../../resources/assets/css' => public_path('assets/backend/css'),
			], 'member-backend-assets-css');

			$this->publishes([
				__DIR__ . '/../../resources/assets/images' => public_path('assets/backend/images'),
			], 'member-backend-assets-images');
		}

		$this->commands([
			MemberBackendMenusCommand::class,
		]);
	}

	public function register()
	{
	}

	protected function mapWebRoutes()
	{
		Route::group([
			'middleware' => ['web', 'admin'],
			'namespace'  => $this->namespace,
		], function ($router) {
			require __DIR__ . '/../Http/routes.php';
		});
	}
}
